package ex05.pyrmont.core;

import org.apache.catalina.Contained;
import org.apache.catalina.Container;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Valve;

public class SimplePipeline implements Pipeline{
	
	//basic valve
	protected Valve basic = null;
	protected Container container;
	protected Valve[] valves = new Valve[0];
	
	public SimplePipeline(Container container) {
		this.container = container;
	}

	@Override
	public void addValve(Valve valve) {
		if (valve instanceof Contained) {
			((Contained)valve).setContainer(container);
		}
		
		synchronized (valves) {
			Valve[] results = new Valve[valves.length+1];
			System.arraycopy(valves, 0, results, 0, valves.length);
			results[valves.length] = valve;
			valves = results;
		}
	}

	@Override
	public Valve getBasic() {
		return basic;
	}

	@Override
	public Container getContainer() {
		return container;
	}

	@Override
	public Valve getFirst() {
		return null;
	}

	@Override
	public Valve[] getValves() {
		return valves;
	}

	@Override
	public boolean isAsyncSupported() {
		return false;
	}

	@Override
	public void removeValve(Valve arg0) {
		
	}

	@Override
	public void setBasic(Valve basic) {
		this.basic = basic;
		((Contained)basic).setContainer(container);
	}

	@Override
	public void setContainer(Container arg0) {
		// TODO Auto-generated method stub
		
	}

}
